<?php require_once('../conn/DBconnect.php');

	$amount = "0";
	if(isset($_POST["store_cash"]))
		$amount = $_POST["store_cash"];
		
	$register_type = "";
	if(isset($_POST["register_type"]))
		$register_type = $_POST["register_type"];
		
	$store_code = "";
	if(isset($_POST["store_code"]))
		$store_code = $_POST["store_code"];
	
	$updateRegSQL = "call SP_KIOSK_REGISTER('".$register_type."','".$store_code."','".$amount."');";
	
	if ($result = mysqli_query($mysqlLink, $updateRegSQL)) {
	    
		if($register_type == 'open')
		{
			$cmsData = mysqli_fetch_array($result);
			
			echo "<div class='formItem'>";
			echo "<div class='formLabel' style='width:400px;'><b>".$cmsData["err_code"]."</b></div>";
			echo "</div>";
			
			echo "<div class='tabularItem'>";
			echo "<div class='formLabel' style='width:400px;'><b>Outlet Code:</b> ".$cmsData["kiosk_code"]."</div>";
			echo "</div>";
			
			echo "<div class='tabularItem'>";
			echo "<div class='formLabel' style='width:400px;'><b>Opening Cash:</b> Php ".number_format($cmsData["kiosk_open_amount"], 2, ".", ",")."</div>";
			echo "</div>";
			
			echo "<div class='tabularItem'>";
			echo "<div class='formLabel' style='width:400px;'><b>Time/Date:</b> ".$cmsData["kiosk_open_time"].",".$cmsData["kiosk_open_date"]."</div>";
			echo "</div>";
		}
		else
		{
			
			$gtotalCount = 0;
			$gtotalAmount = 0;
			$err_code_set = false;
			
			while ($row = mysqli_fetch_assoc($result)) {
				
				if($err_code_set == false)
				{
					if($row["err_id"] == '-1')
					{
						echo "<div class='formItem'>";
						echo "<div class='formLabel' style='width:400px;'><font color='#ff0000'><b>".$row["err_code"]."</b></font></div>";
						echo "</div>";
						return;
					}
					else
					{
						echo "<div class='formItem'>";
						echo "<div class='formLabel' style='width:400px;'><b>".$row["err_code"]."</b></div>";
						echo "</div>";
					}
						
					$err_code_set = true;
					
					echo "<div class='tabularItem'>";
					echo "<div class='formLabel' style='width:120px;text-align:center;'><b>Race Category</b></div>";
					echo "<div class='formLabelRight' style='width:120px;'><b>Count</b></div>";
					echo "<div class='formLabelRight' style='width:120px;'><b>Amount</b></div>";
					echo "</div>";
				}
				
				$gtotalCount += $row["total_reg"];
				$gtotalAmount += $row["total_amount"];
				
				$totalAmt = number_format($row["total_amount"], 2, ".", ",");
				
				echo "<div class='tabularItem'>";
				echo "<div class='formLabel' style='width:120px;text-align:center;'>- ".$row["race_code"]." -</div>";
				echo "<div class='formLabelRight' style='width:120px;'>".$row["total_reg"]."</div>";
				echo "<div class='formLabelRight' style='width:120px;'>".$totalAmt."</div>";
				echo "</div>";
			}
			
			echo "<div>";
			echo "<div style='width:580px;padding:0px 10px;'>";
			echo "<hr class='hrDashed'>";
			echo "</div></div>";
			
			$gtotalAmount = number_format($gtotalAmount, 2, ".", ",");
				
			echo "<div class='tabularItem'>";
			echo "<div class='formLabelRight' style='width:120px;'><b>Total</b></div>";
			echo "<div class='formLabelRight' style='width:120px;'><b>".$gtotalCount."</b></div>";
			echo "<div class='formLabelRight' style='width:120px;'><b>".$gtotalAmount."</b></div>";
			echo "</div>";
		}
		
	    $result->close();
	}
	else
		echo "Register ".$register_type." failed.";
	
	mysqli_close($mysqlLink);

?>